const ctx =wx.createCanvasContext('myCanvas')
Page({
  data:{
    mosaic:true,
  },
  open(){  //打开图片
    wx.chooseImage({
      count: 1,
    }).then(res=>{
      console.log(res)
      ctx.drawImage(res.tempFilePaths[0],0,0,400,380)
      ctx.draw()
    })
  },
  move(e){
console.log(e)
if(this.data.mosaic){
ctx.setFillStyle('blue')
ctx.fillRect(e.touches[0].x,e.touches[0].y,10,10)
ctx.fillRect(e.touches[0].x+10,e.touches[0].y+10,10,10)
ctx.setFillStyle('yellow')
ctx.fillRect(e.touches[0].x+10,e.touches[0].y,10,10)
ctx.fillRect(e.touches[0].x,e.touches[0].y+10,10,10)
ctx.draw(true)
}else{
  ctx.clearRect(e.touches[0].x,e.touches[0].y,20,20)
  ctx.draw(true)
}
  },
  clear(){
    this.setData({
      mosaic:false
    })
  },
  mosaic(){
    this.setData({
      mosaic:true
    })
  },
  save(){  //保存图片
     wx.canvasToTempFilePath({   //获取图片的路劲
      canvasId: 'myCanvas', 
    }).then(res=>{          //获取成功
      console.log(res)
      console.log('用户点击了保存')
     wx.saveImageToPhotosAlbum({   //保存图片到相册
       filePath: res.tempFilePath,
     }).then(res=>{     //保存成功   提示
       wx.showToast({
         title:'保存图片成功',
       })
     })
    })
  },
  seal(res){
    ctx.setFillStyle('pink')
    ctx.setFontSize(36)
    ctx.fillText('21121128吴锦程',0,200)
    ctx.draw(true)
  },
  onShareAppMessage(){
    return{
      title:'吴锦程的图片',
      desc:'有趣的马赛克',
      path:'/pages/work12/index'
    }
  }
})